package thread;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-05-11
 * Time：13:36
 */
public class Demo9 {
    private static boolean isQuit = false;
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while (!isQuit) {
                System.out.println("thread is running..");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("thread is finished! ");
        });
        thread.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        isQuit = true;
    }
}
